//
//  QuestionHeaderTableView.m
//  FreshBee
//
//  Created by 姜 祥云 on 16/10/16.
//  Copyright © 2016年 iOS013. All rights reserved.
//

#import "QuestionHeaderTableView.h"
#import "QuestionGroup.h"

@interface QuestionHeaderTableView ()
@property (nonatomic,weak)UIButton *btn;


@end


@implementation QuestionHeaderTableView
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithReuseIdentifier:reuseIdentifier];
    if(self){
        [self createMySubView];
        
    }
    return self;
}
-(void)createMySubView
{
    UIButton *btn = [[UIButton alloc]init];
    self.btn=btn;
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
  
}
-(void)setQuestionGroup:(QuestionGroup *)questionGroup
{
    _questionGroup=questionGroup;
    [self.btn setTitle:questionGroup.title forState:UIControlStateNormal];
    [self.btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [self.btn setImage:[UIImage imageNamed:@"cell_arrow_up_accessory"] forState:UIControlStateNormal];
    [self.btn setImage:[UIImage imageNamed:@"cell_arrow_down_accessory"] forState:UIControlStateSelected];
    [self.btn setBackgroundImage:[UIImage imageNamed:@"buddy_header_bg"] forState:UIControlStateNormal];
    
    [self.btn setBackgroundImage:[UIImage imageNamed:@"buddy_header_bg_highlighted"] forState:UIControlStateHighlighted];
    
    self.btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;

    self.btn.imageEdgeInsets = UIEdgeInsetsMake(0, [UIScreen mainScreen].bounds.size.width * 0.95 , 0, 0);
//    self.btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 15);
//    self.btn.contentEdgeInsets=UIEdgeInsetsMake(0, 0, 0, 15);

    
//    self.btn.titleEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
    if(self.questionGroup.open){
        self.btn.imageView.transform = CGAffineTransformMakeRotation(2*M_PI_2);
    }else{
        
        self.btn.imageView.transform = CGAffineTransformIdentity;
    }
    
    
    //改变图片的拉伸方式
    self.btn.imageView.contentMode = UIViewContentModeCenter;
    
    //让超出控件的部分不剪切
    self.btn.imageView.clipsToBounds = NO;

}
- (void)btnClick{
    
    //1. 获取到对应的组
    //    self.friendGroup;
    
    
    
    
    //代理创建 3: 调用方法
    //刷新tableView
    if ([self.delegate respondsToSelector:@selector(btnClickWithQuestionHeaderTableView:)]) {
        [self.delegate btnClickWithQuestionHeaderTableView:self];
    }
    
    
    
    
    
}
- (void)layoutSubviews{
    
    //     NSLog(@"layoutSubviews -->头View的frame  %@",NSStringFromCGRect(self.frame));
    
    
    self.btn.frame = CGRectMake(0, 0,self.bounds.size.width, self.bounds.size.height);
}


@end
